<?php

class Resources {

    public $actions = 0;
    public $buys = 0;
    private $money = null;
    public $victoryTokens = 0;
    public $pirateshipTokens = 0;
    public $coinTokens = 0;

    public function __construct($actions = 1, $buys = 1, $money = null, $victorytokens = 0, $pirateshiptokens = 0, $cointokens = 0) {
        $this->actions = $actions;
        $this->buys = $buys;
        if (!$money) {
            $money = new Price;
        }
        $this->money = $money;
        $this->victoryTokens = $victorytokens;
        $this->pirateshipTokens = $pirateshiptokens;
        $this->coinTokens = $cointokens;
    }

    public function save($gid, $name) {
        $db = DBUtils::Create();
        $coins = $this->money->getCoins();
        $potions = $this->money->getPotions();
        $db->saveResources($gid, $name, $this->actions, $this->buys, $coins, $potions, $this->victoryTokens, $this->pirateshipTokens, $this->coinTokens);
    }

    public function startTurn() {
        $this->actions = 1;
        $this->buys = 1;
        $this->money = new Price(0);
    }

    public function endTurn() {
        $this->actions = 1;
        $this->buys = 1;
        $this->money = new Price(0);
    }

    public function addActions($actions) {
        $this->actions += $actions;
    }

    public function addBuys($buys) {
        $this->buys += $buys;
    }

    public function addMoney($price) {
        $this->money = $this->money->add($price);
    }
    
    public function setMoney($price) {
        $this->money = $price;
    }
    
    public function addVictoryTokens($tokens) {
        $this->victoryTokens += $tokens;
    }
    
    public function addCoinTokens($tokens) {
        $this->coinTokens += $tokens;
    }
    
    public function getPirateShipTokens() {
        return $this->pirateshipTokens;
    }
    
    public function getCoinTokens() {
        return $this->coinTokens;
    }

    public function addPirateShipToken() {
        $this->pirateshipTokens += 1;
    }
    
    public function getMoney() {
        return $this->money;
    }

}

?>